package goleetcode

func missingRolls(rolls []int, mean int, n int) []int {
	m := len(rolls)
	total := m + n
	totalCnt := total * mean
	sum := 0
	for _, v := range rolls {
		sum += v
	}
	var ans float32
	ans = float32(totalCnt-sum) / float32(n)
	if ans > 6 || (totalCnt-sum)/n < 1 {
		return []int{}
	}
	res := make([]int, n)
	remain := totalCnt - sum
	tmp := remain/n
	for i := range res {
		res[i] = tmp
		remain -= tmp
	}
	for i := n - 1; remain > 0 && i >= 0; i-- {
		if remain > 0 {
			res[i]++
			remain--
		}
	}
	return res
}